//
//  EmoticonAttachment.swift
//  表情键盘
//
//  Created by 孙明海 on 16/2/18.
//  Copyright © 2016年 孙明海. All rights reserved.
//

import UIKit

class EmoticonAttachment: NSTextAttachment {
    var emoticon: Emoticon
    
    func imageText(font: UIFont) -> NSAttributedString {
        let lineHight = font.lineHeight
        bounds = CGRectMake(0, -4, lineHight, lineHight)
        image = UIImage(contentsOfFile: emoticon.imagePath)
        let attr = NSMutableAttributedString(attributedString: NSAttributedString(attachment: self))
        attr.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: 1))
        return attr
    }
    
    init(emoticon: Emoticon) {
        self.emoticon = emoticon
        super.init(data: nil, ofType: nil)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
